package day_2022_12_to_3.year2023;

/**
 * @author haomin
 * @date 2023/01/21 10:55
 **/
public class Day1_21_Num1824 {
    static class Solution {
        public static int minSideJumps(int[] obstacles) {
            int flag = 1, side = 2, ans = 0;
            for(int i = 0; i < obstacles.length; i++){
                if(flag == 1){
                    if(obstacles[i] != side)
                        continue;
                    if(obstacles[i-1] == 1)   //如果上一步的1有障碍
                        side = side^2^3;
                    else if(obstacles[i-1] == 2)   //如果上一步的2有障碍
                        side = side^1^3;
                    else if(obstacles[i-1] == 3)   //如果上一步的3有障碍
                        side = side^1^2;
                    else
                        flag = 0;
                    ans++;
                }
                else{
                    if(side == 2 && obstacles[i] != 1 && obstacles[i] != 3)
                        continue;
                    if(side == 1 && obstacles[i] != 2 && obstacles[i] != 3)
                        continue;
                    if(side == 3 && obstacles[i] != 1 && obstacles[i] != 2)
                        continue;
                    if(side == 2)
                        side = obstacles[i]^1^3;

                    else if(side == 1)
                        side = obstacles[i]^2^3;

                    else
                        side = obstacles[i]^1^2;
                    flag = 1;
                }
            }
            return ans;
        }
    }
}